home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / clipper / ks94an.zip / KFILE.CH < prev    next >
Text File  |  1993-04-13  |  8KB  |  219 lines

  1. LOCAL FA
  2. LOCAL KA
  3.  
  4. #xtran FILE_BEGIN <file> => if !file(#<file>);FA := {};KA=Select();Select 0 ;
  5.  
  6. #xtran FILE_END <newfile> => ;
  7.         dbCreate(#<newfile>, FA); use ; select (KA) ; endif
  8.  
  9. #xtran BEGIN_FILE <file> => if !file(#<file>);FA := {};KA=Select();Select 0 ;
  10.  
  11. #xtran END_FILE <newfile> => ;
  12.         dbCreate(#<newfile>, FA); use ; select (KA) ; endif
  13.  
  14. #xtran FLD <id1>, <id2> [,<id3> [,<id4>]] => ;
  15.         aadd(FA,{#<id1>,#<id2> ,#<id3> ,#<id4> }) ;;
  16.         FA\[len(FA),3] := iif(!empty(FA\[len(FA),3]),val(FA\[len(FA),3]),0) ;;
  17.         FA\[len(FA),4] := iif(!empty(FA\[len(FA),4]),val(FA\[len(FA),4]),0) ;
  18.  
  19. /***********************************************************************************
  20.  
  21. USAGE NOTES:
  22.  
  23. FILE_BEGIN
  24. FILE_END
  25. FLD
  26.  
  27. FA ARRAY NAME - FA reserved identifier
  28. -----------------------------------------------------
  29.  
  30. The FA array name (Short for File Array) was chosen because it is short:
  31. only two characters.  This became necessary when the array was referenced
  32. six times in one line.  It would be too large to easily read, and since this
  33. code is "FOR THE PRE-PROCs EYES ONLY", it doesn' matter much.  Still, the
  34. FA identifier is reserved.
  35.  
  36.  
  37. FILE_BEGIN, FILE_END & FLD PREPROCESSOR DIRECTIVES
  38. -----------------------------------------------------
  39.  
  40. Allows an abbreviated form of creating databases from extended structure files.
  41. The first example is a typical method of creating a database, and the second
  42. is the legal abbreviated form.
  43.  
  44. 1. Use no quotes around text or numeric.
  45. 2. Field Data can simply be typed and separated by a comma.
  46. 3. Length/Decimals Optional for Date, Memo, Integer Fields)
  47. 4. File name MUST have file name extention.
  48. 5. The identifier FA is reserved.
  49.  
  50. Briefly, the purpose is to facilitate an easy method of checking the
  51. existence of a particular file, and creating it if necessary.  The typical
  52. use is to include these directives at the beginning of every application for
  53. two reasons:  (1) to initially create the necessary databases the FIRST time
  54. the program is run (negating the need for dBASE or DBU.EXE) and (2) regularly
  55. checking the existence of the files each time the program runs to see if any
  56. have been deleted.  Once created, these directives do nothing if the file is
  57. present.  If the file is not present, it is created according to the FLD
  58. definitions.  Thus, accidental deletions will not cause a run-time error.
  59.  
  60. The Directives amount to the following:
  61.  
  62. IF .NOT. FILE("YOURFILE.DBF")             // FILE_BEGIN YOURFILE.DBF
  63.  
  64.     CREATE TEMP
  65.  
  66.     DEFINE FIELDS                         // FLD ...
  67.     .                                     // FLD ...
  68.     .                                     // FLD ...
  69.     .                                     // FLD ...
  70.  
  71.     CREATE YOURFILE.DBF FROM TEMP
  72.     ERASE TEMP
  73.  
  74. ENDIF                                     // END_FILE YOURFILE.DBF
  75.  
  76.                                CAUTION
  77. ---------------------------------------------------------------------------
  78.  
  79. MS-DOS utilities are available for unerasing an accidentally erased file.
  80. However, this task is made much more difficult if since the original file
  81. was deleted, another has been created with the SAME FILE NAME.  Thus, the
  82. potential for recovery is drastically improved when (1), no other file has
  83. been created with the same name, and (2) as little disk writing as possible
  84. has occured since the accidental erasure.
  85.  
  86. These directives will create the database named by FILE_BEGIN.  If the file
  87. originally WAS present, and then accidentally deleted, and these directives
  88. re-create the database with the same name, you will have made recovery of the
  89. original very, very difficult.  Use only in cases of transient databases which
  90. can be easily re-created or else add safegaurds. *
  91.  
  92. * Continued Next Page 
  93.  
  94. One possible solution to the "overwriting originals" problem may be to check
  95. your data files via a separate routine that uses FILE_BEGIN/END only where
  96. permissible, or use a routine that adds a prompt before creating:
  97.  
  98. START OF APPLICATION
  99.  
  100. // Check Critcal Files
  101.  
  102. if !FILE('critical.dbf')
  103.     if Ask_User('Would you like to create the missing Critical File?) = 'Y'
  104.  
  105.         FILE_BEGIN CRITICAL.DBF
  106.             FLD ...
  107.             FLD ...
  108.             FLD ...
  109.         FILE_END CRITICAL.DBF
  110.     else
  111.         Tell_User('Not Created, Contact CAD Representative...)
  112.     endif
  113. endif
  114.  
  115. // Check Transient or Non-Ccritical Files
  116.  
  117. FILE_BEGIN NON_CRITICAL.DBF
  118.  
  119.     FLD ...
  120.     FLD ...
  121.     FLD ...
  122.  
  123. FILE_END NON_CRITICAL.DBF
  124.  
  125. *****************************************************************************
  126.  
  127. In the case of CRITICAL.DBF, you make the file existence check redundant,
  128. (YOU check for it, and then FILE_BEGIN xxxxxx.xxx checks for it again) but
  129. it allows YOU to get control before FILE_BEGIN does; creating the file only
  130. after you have had an opportunity to approve.  Had you not added the statement
  131. "IF !FILE()", the FILE_BEGIN directive would have checked and created the
  132. missing file without question, thus making any possibility of retreiving an
  133. accidentally erased file much more remote.
  134.  
  135. Concerning the Identifier Names
  136. -------------------------------
  137.  
  138. The identifier FLD (for Field structure), MUST be in UPPER CASE in your
  139. source code, both in the #xtranslate definition, and in the source code
  140. instance.  If you wish any other form, you need to modify both accordingly.
  141. I.E. If you want to use "Fld" instead of "FLD", you must change both.
  142. In a nutshell, the #xtranslate directive IS case sensitive.  You do not have
  143. to use "FLD", you can change it to anything you like, perhaps "MoRgRiFy"
  144. if you like.
  145.  
  146. Kirby L. Wallace
  147.  
  148. * Examples Follow on Next Page 
  149.  
  150. ***************************
  151. * STANDARD CLIPPER METHOD *
  152. ***************************
  153.  
  154. if !file('SYSTEM.DBF')
  155.         
  156.         create temp
  157.         
  158.         APPEND BLANK
  159.         REPLACE field_name WITH 'USER', ;
  160.                 field_type WITH 'C', ;
  161.                 field_len  WITH 10, ;
  162.                 field_dec  WITH 0
  163.         
  164.         APPEND BLANK
  165.         REPLACE field_name WITH 'SYSTEM', ;
  166.                 field_type WITH 'C', ;
  167.                 field_len  WITH 10, ;
  168.                 field_dec  WITH 0
  169.         
  170.         APPEND BLANK
  171.         REPLACE field_name WITH 'SECURITY', ;
  172.                 field_type WITH 'N', ;
  173.                 field_len  WITH 2, ;
  174.                 field_dec  WITH 0
  175.         
  176.         APPEND BLANK
  177.         REPLACE field_name WITH 'APPL_ADM', ;
  178.                 field_type WITH 'L'
  179.         
  180.         APPEND BLANK
  181.         REPLACE field_name WITH 'HAVE_MAIL', ;
  182.                 field_type WITH 'L'
  183.         
  184.         APPEND BLANK
  185.         REPLACE field_name WITH 'LAST_USE', ;
  186.                 field_type WITH 'D'
  187.         
  188.         APPEND BLANK
  189.         REPLACE field_name WITH 'EXPIRES', ;
  190.                 field_type WITH 'D'
  191.         
  192.         
  193.         create SYSTEM from TEMP
  194.         use
  195.         erase TEMP.DBF
  196.         
  197. endif
  198.  
  199. * Continues Next Page 
  200.  
  201. **************************************************************************
  202. * The following lines are the equivalent w/ the #xtranslate directives   *
  203. **************************************************************************
  204.         
  205. FILE_BEGIN SYSTEM.DAT
  206.         
  207.     FLD USER,     C, 10
  208.     FLD SYSTEM,   C, 10
  209.     FLD SECURITY, N, 2
  210.     FLD BALANCE,  N, 8, 2
  211.     FLD APPL_ADM, L
  212.     FLD EXPIRES,  D
  213.     FLD LAST_USE, D
  214.         
  215. FILE_END SYSTEM.DAT
  216.  
  217. ******************************************************************************/
  218.  
  219.